Learn about sql server extract month from date, we have the largest and most updated sql server extract month from date information on alibabacloud.com
Declare @ DT datetimeSet @ dt = getdate ()
Declare @ number intSet @ number = 3
-- 1. Specify the first or last day of the year-- The First Day is January 1, and the last day is December 31.
-- A. The first day of the yearSelect convert (char (5), @ DT, 120) + '1-1'
-- B. The last day of the yearSelect convert (char (5), @ DT, 120) + '12-31'
-- 2. Specify the first or last day of the quarter where the date is located.-- A. The first day of t
Label:Select CONVERT (varchar), DATEPART (YYYY,A.FSSJ) as years,--get yearCONVERT (varchar), DATEPART (MM,A.FSSJ) as months,--get monthSUM (case if b.fszt in (' 1 ', ' 2 ') then A.cfs else 0 end) as Fscgnumber,SUM (A.CFS) as FsnumberFrom T_mtn_sendrecord AINNER JOIN T_mtn_sendnote B on A.DXDM=B.DXDMGROUP by CONVERT (varchar), DATEPART (YYYY,A.FSSJ), convert (varchar), DATEPART (MM,A.FSSJ))ORDER by CONVERT (int,convert (varchar), DATEPART (YYYY,A.FSSJ)),--year converted from string to numberCONVE
, @getDateYear int, @getDateMonth int, @returnDate datetime set @getDate =cast (@yourDate as datetime) set @getDateYear =year (@getDate) set @getDateMonth = Month (@getDate) set @returnDate =cast (str (@getDateYear) + '-' +str (@getDateMonth) + ' -01 ' as datetime)-1 return CONVERT (varchar, @returnDate) End
6 below the date of the beginning of this
The first day of the month on which the given date is calculated
The trick is to calculate the
number of time intervals between the current date and "1900-01-01" and then add it to "1900-01-01" to get a special date, a technique that can be used---to calculate many different dates.
DECLARE @
--the first day of last month SELECT CONVERT(CHAR(Ten),DATEADD(Month,-1,DATEADD(DD,- Day(GETDATE())+1,GETDATE())),111) SELECT DATEADD(MM,DATEDIFF(MM,0,DateAdd(Month,-1,getdate())),0) --the last day of last month SELECT CONVERT(CHAR(Ten),DATEADD(MS,-3,DATEADD(MM,DATEDIFF(MM,0,getdate()),0)),111)+'23:59:59' Select DateA
DECLARE @date datetime
Set @date =getdate ()
--The current month first day plus 2 months minus 1 days
Select DATEADD (Day,-1,dateadd (Month,2,dateadd (month,0, @date), 0)) as ' last day of next
Label:1. First day of last monthSELECT CONVERT (CHAR), DATEADD (Month,-1,dateadd (Dd,-day (GETDATE ()) +1,getdate ()), 111)2. Last day of last monthSELECT CONVERT (CHAR), DATEADD (Ms,-3,dateadd (mm, DATEDIFF (Mm,0,getdate ()), 0)), 111) + ' 23:59:59 '3, the first day of the monthSELECT CONVERT (CHAR), DATEADD (Dd,-day (GETDATE ()) +1,getdate ()), 111)4, the last day of this monthSELECT CONVERT (CHAR), DATEADD (Ms,-3,dateadd (Mm,datediff (M,0,getdate (
-- Added the weekly times of the month and year of the date!-- Sunday is counted as "last week "! (Note the differences between weekofyear, weekofmonth, myweekofyear, and myweekofmonth)-- Note that the datename value varies depending on the SQL Server language version or date
From: http://blog.csdn.net/timefile/article/details/6573821
Select dateadd (DD,-day (dateadd (month,-1, getdate () + 1, dateadd (month,-1, getdate ()/* 1st day of last month */Select dateadd (DD,-day (getdate (), getdate ()/* end of last month */Select dateadd (DD,-day (getdate () + 1, getdate ()/* 1st day of this
as follows:
Value
Abbreviation (SQL Server)
Access and ASP
Description
Year
Yy
yyyy
Year 1753 ~ 9999
Quarter
Qq
Q
Quarter 1 ~ 4
Month
Mm
M
Month 1 ~ 12
Day of the Year
Dy
Y
The number of days in a y
week of =datename (weekday, ' 2004-10-15 ')function parameters/FunctionsGetDate () returns the current date and time of the systemDateDiff (INTERVAL,DATE1,DATE2) returns the difference between Date2 and date1 two dates in the interval specified date2-date1DATEADD (interval,number,date) with the date specified in interval, plus numberDatePart (interval,
(Datetime,convert (char (8), @dt, 120) + ' 1 ')--b. The last day of the monthSELECT DATEADD (Day,-1,convert (char (8), DATEADD (month,1, @dt), 120) + ' 1 ')--4. Any day of the week on which the specified date is locatedSELECT DATEADD (Day, @number-datepart (Weekday, @dt), @dt)--5. Any day of the week on which the specified date is located--a. Sunday as the 1th d
Label:The DateDiff () function and the GETDATE () function are needed when you are doing SQL Server development and sometimes need to get the data in the table today, yesterday, this week, last week, this month, and last month.DATEDIFF (DatePart, StartDate, EndDate)Explanation: Calculating the time differenceDatepare Value: Year | Quarter |
SQL statement used to calculate the number of days in the month and quarter of a given date
SQL statement used to calculate the number of days in the month and quarter of a given date
SQL
Label:The DateDiff () function and the GETDATE () function are needed when you are doing SQL Server development and sometimes need to get the data in the table today, yesterday, this week, last week, this month, and last month. DATEDIFF (DatePart, startdate, enddate) definition: Calculate time difference Datepare value
Calculate the SQL statement of the last day of the last month of the given date.
Calculate the SQL statement of the last day of the last month of the given date.
Calculate the SQL s
Tags: englishromcopytimegroup by date settings mon language Tags: datepart function SQL used date month year grouping group by group 2013-12-26 15:31 20764 People read reviews (1) Favorite report Category: SQL Server (21) Copyrig
date as an integer value. This section is specified by DatePart. DATEPART (dd, date) is equivalent to day (date) DATEPART (mm, date) equals month (date) DATEPART (yy, date) is equivale
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.